package com.zkca.xf.presenter;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.FragmentEvent;
import com.zkca.xf.base.BaseFragmentPresenter;
import com.zkca.xf.manager.DataManager;
import com.zkca.xf.model.javabean.NewsBeab;
import com.zkca.xf.model.javabean.UserBean_W;
import com.zkca.xf.model.javabean.uploadbean.RequestUser;
import com.zkca.xf.view.LogoutView;

import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DefaultObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by li on 2019/1/7.
 */

public class LogOutPersenter extends BaseFragmentPresenter {
    private DataManager dataManager;
    private LogoutView personalView;
    public LogOutPersenter(LifecycleProvider<FragmentEvent> provider,LogoutView personalView) {
        super(provider);
        this.personalView = personalView;
        dataManager = DataManager.getInstance();
    }

    //获取新闻信息（id,page,pageSize）
    public void Logout(RequestUser requestInspect) {
        dataManager.Logout(requestInspect)
                .subscribeOn(Schedulers.io())// 在子线程中进行Http访问
                .observeOn(AndroidSchedulers.mainThread())// UI线程处理返回接口
                .compose(getProvider().<UserBean_W>bindUntilEvent(FragmentEvent.DESTROY))// onDestroy取消订阅
                .subscribe(new DefaultObserver<UserBean_W>() {// 订阅
                    @Override
                    public void onNext(UserBean_W newsBeab) {
                        personalView.Logout(newsBeab);
                    }

                    @Override
                    public void onError(Throwable e) {
                        personalView.showError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        personalView.hideProgressDialog();
                    }
                });
    }

}
